package org.yang.novel.down.service.impl;

import static org.yang.common.Msg.*;

import org.yang.common.Msg;
import org.yang.novel.down.dao.PageMapper;
import org.yang.novel.down.entity.Page;
import org.yang.novel.down.service.PageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 章节服务实现
 * @author shichenyang
 * @email gyv12345@163.com
 * @date 2019/01/07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PageServiceImpl implements PageService {
    @Resource
    private PageMapper pageMapper;

    @Override
    public Msg addPage(Page page) {
        int i=  pageMapper.insert(page);
        return i>0?ok(ADD_SUCCESS):err(ADD_ERR);
    }

    @Override
    public Msg updatePage(Page page) {
        int i= pageMapper.updateByParam(page);
        return i>0?ok(UPDATE_SUCCESS):err(UPDATE_ERR);
    }

    @Override
    public Msg delPage(Page page) {
        int i=pageMapper.del(page.getId());
        return i>0?ok(DEL_SUCCESS):err(DEL_ERR);
    }

    @Override
    public PageInfo getPages(Page page, Integer p, Integer limit) {
        PageHelper.startPage(p,limit);
        List<Page> pages=pageMapper.list(page);
        PageInfo pi=new PageInfo(pages);
        return pi;
    }
}
